class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int n=nums.size();
        if(n==1) return 1;
        vector<int> arr;
        for(int i=0;i<n-1;++i)
        {
            if(nums[i+1]-nums[i]!=0)
                arr.push_back(nums[i+1]-nums[i]);
        }
        if(arr.empty()) return 1;
        int ret=1;
        vector<int> dp(arr.size(),1);
        for(int i=1;i<arr.size();++i)
        {
            if((arr[i]>0&&arr[i-1]<0)||(arr[i]<0&&arr[i-1]>0))
                dp[i]=dp[i-1]+1;
            else
                dp[i]=max(dp[i-1],dp[i]);
            ret=max(ret,dp[i]);
        }
        return ret+1;
    }
};
